function CardReadError(errcode ,errno ,errmsg) {
	this.errcode = errcode;
	this.errno = errno;
	this.errmsg = errmsg;
}
var errors = new Array(
		new CardReadError("ERROR_SUCCESS","0","成功"),
		new CardReadError("ERROR_DEVICE_OK","1","设备已连接"),
		new CardReadError("ERROR_DEVICE_DOWN","0","设备未连接"),
		new CardReadError("ERROR_STATUS_ACTIVE","1","上电状态"),
		new CardReadError("ERROR_STATUS_DEACTIVE","0","下电状态"),		
		new CardReadError("ERROR_ACTIVE_CPU","-1000","卡未放置读卡区或CPU卡上电异常"),
		new CardReadError("ERROR_DEACTIVE_CPU","-1001","CPU卡下电异常"),
		new CardReadError("ERROR_ACTIVE_SAM","-1002","SAM卡上电异常"),
		new CardReadError("ERROR_DEACTIVE_SAM","-1003","SAM卡下电异常"),
		new CardReadError("ERROR_FIND_CPU","-1004","CPU卡寻卡异常"),
		new CardReadError("ERROR_SET_CPU","-1005","CPU卡设置异常"),
		new CardReadError("ERROR_RESET_CPU","-1006","CPU卡上电复位异常"),
		new CardReadError("ERROR_HALT_CPU","-1007","CPU卡下电异常"),
		new CardReadError("ERROR_RESET_SAM","-1008","SAM卡座上电复位异常"),
		new CardReadError("ERROR_SET_SAM","-1009","SAM卡座设置异常"),
		new CardReadError("ERROR_CMD_SAM_PSE","-1010","发送SAM选PSE命令异常"),
		new CardReadError("ERROR_CMD_SAM_TERMINAL_NO","-1011","发送读取SAM卡号终端号异常"),
		new CardReadError("ERROR_CMD_SAM_ADF","-1012","发送SAM选ADF命令异常"),
		new CardReadError("ERROR_CONNECT_DEVICE","-1013","连接设备异常"),
		new CardReadError("ERROR_DISCONNECT_DEVICE","-1014","断开设备异常"),		
		new CardReadError("ERROR_SELECT_MF","-2000","选择主文件3F00失败"),
		new CardReadError("ERROR_SELECT_DF_TRAFFIC","-2001","选择DF公交应用失败"),
		new CardReadError("ERROR_SELECT_DF_MONTHTICKET","-2002","选择DF月票应用失败"),
		new CardReadError("ERROR_SELECT_DF_3F1E","-2003","选择DF文件3F1E失败"),
		new CardReadError("ERROR_SELECT_DF_0005","-2004","选择DF文件0005失败"),
		new CardReadError("ERROR_READ_RECORD","-2005","读记录文件失败"),
		new CardReadError("ERROR_GET_CARDNO","-2006","读取卡号失败"),
		new CardReadError("ERROR_GET_WALLET_BALANCE","-2007","读取余额失败"),
		new CardReadError("ERROR_GET_BALANCE_TRAFFIC","-2008","查询公交余额失败"),
		new CardReadError("ERROR_GET_BALANCE_MONTHTICKET","-2009","查询月票余额失败"),
		new CardReadError("ERROR_INVALID_CARDDATE","-2010","卡不在有效期"),
		new CardReadError("ERROR_NOT_SAME_CARD","-2011","非同一张卡"),
		new CardReadError("ERROR_OPEN_TRADE","-2012","开通应用失败"),
		new CardReadError("ERROR_CLOSE_TRADE","-2013","关闭应用失败"),
		new CardReadError("ERROR_GET_APP_STATUS","-2014","读取应用状态失败"),
		new CardReadError("ERROR_QUERY_APP_STATUS","-2015","查询应用状态异常"),
		new CardReadError("ERROR_QUERY_STATUS_SHBZ","-2016","查询社会保障应用状态失败"),
		new CardReadError("ERROR_QUERY_STATUS_JZZ","-2017","查询居住证应用状态失败"),
		new CardReadError("ERROR_QUERY_STATUS_GJJ","-2018","查询公积金应用状态异常"),
		new CardReadError("ERROR_QUERY_STATUS_JZYY","-2019","查询就诊应用状态异常"),
		new CardReadError("ERROR_QUERY_STATUS_XEXF","-2020","查询小额消费应用状态异常"),
		new CardReadError("ERROR_QUERY_STATUS_TSG","-2021","查询图书馆应用状态异常"),
		new CardReadError("ERROR_QUERY_STATUS_YL","-2022","查询园林应用状态异常"),
		new CardReadError("ERROR_QUERY_STATUS_GJ","-2023","查询公交应用状态异常"),
		new CardReadError("ERROR_QUERY_STATUS_DZZF","-2024","查询定向支付应用状态异常"),
		new CardReadError("ERROR_QUERY_STATUS_WS","-2025","查询卫生应用状态异常"),
		new CardReadError("ERROR_EP_LOAD_INIT","-2026","EP圈存初始化失败"),
		new CardReadError("ERROR_EP_LOAD","-2027","EP圈存失败"),
		new CardReadError("ERROR_EP_PURCHASE_INIT","-2028","EP消费初始化失败"),
		new CardReadError("ERROR_EP_PURCHASE","-2029","EP消费失败"),
		new CardReadError("ERROR_SAM_CALC_MAC","-2030","SAM计算MAC失败"),
		new CardReadError("ERROR_SAM_VERIFY_MAC","-2031","SAM验证MAC失败"),
		new CardReadError("ERROR_WRITE_WALLET","-2032","写电子钱包失败"),
		new CardReadError("ERROR_PUT_WALLET_BALANCE","-2033","写账务余额失败"),
		new CardReadError("ERROR_MAC_VERIFY","-2034","MAC比对失败"),
		new CardReadError("ERROR_EXCEED_BALANCE","-2035","查询余额超过限额异常"),
		new CardReadError("ERROR_GET_RND","-2036","获取随机数失败"),
		new CardReadError("ERROR_DELIVERY","-2037","分散失败"),
		new CardReadError("ERROR_ENCRYPTION","-2038","加密失败"),
		new CardReadError("ERROR_GET_RESPONSE","-2039","GET RESPONSE失败"),
		new CardReadError("ERROR_EXTERNAL_AUTH","-2040","外部认证失败"),
		new CardReadError("ERROR_READ_BIN_FILE","-2041","读取二进制文件失败"),
		new CardReadError("ERROR_UPDATE_BIN_FILE","-2042","更新二进制文件失败"),
		new CardReadError("ERROR_QUERY_BALANCE","-2043","查询余额失败"),
		new CardReadError("ERROR_APDU_CPU","-2044","CPU APDU失败"),
		new CardReadError("ERROR_APDU_SAM","-2045","SAM APDU失败"),
		new CardReadError("ERROR_READ_DATE","-2046","读取卡有效期失败"),
		new CardReadError("ERROR_READ_FENSAN","-2047","读分散因子失败"),
		new CardReadError("ERROR_VERIRY_PIN","-2048","验证PIN失败"),
		new CardReadError("ERROR_FIND_LOGIC_CARD","-2049","请检查卡片是否放置在读卡器上，或卡片为坏卡"),
		new CardReadError("ERROR_GET_LOGIC_INFO","-2050","读逻辑加密卡信息失败"),
		new CardReadError("ERROR_GET_LOGIC_LAST_CZ_INFO","-2051","读逻辑加密卡最新充资信息失败"),
		new CardReadError("ERROR_GET_LOGIC_BALANCE","-2052","读取逻辑加密卡余额失败"),
		new CardReadError("ERROR_LOGIC_LOAD","-2053","逻辑加密卡写卡失败"),
		new CardReadError("ERROR_LOGIC_PURCHASE","-2054","逻辑加密卡消费失败"),
		new CardReadError("ERROR_BLACK_LIST_CARD","-2055","黑名单卡"),
		new CardReadError("ERROR_NOT_SUFFICIENT_FUNDS","-2056","余额不足"),
		new CardReadError("ERROR_READ_BLOCK","-2057","读块错误"),
		new CardReadError("ERROR_WRITE_BLOCK","-2058","写块错误"),
		new CardReadError("ERROR_RESTORE_BLOCK","-2059","restore错误"),
		new CardReadError("ERROR_TRANSFER_BLOCK","-2060","transfer错误"),
		new CardReadError("ERROR_DECREMENT_BLOCK","-2061","decrement错误"),
		new CardReadError("ERROR_LOAD_AND_AUTH","-2062","加载认证密钥失败"),
		new CardReadError("ERROR_LOAD_KEY","-2063","加载密钥错误"),
		new CardReadError("ERROR_AUTHENTICATION","-2064","认证失败"),
		new CardReadError("ERROR_WRITE_RECORD","-2065","写交易记录失败"),
		new CardReadError("ERROR_VERIRY_EXPIRES","-2066","判断卡有效期异常"),
		new CardReadError("ERROR_EXCEED_EXPIRES","-2067","卡有效期超过"),
		new CardReadError("ERROR_SWITCH_HH","-2068","切换华虹算法出错"),
		new CardReadError("ERROR_ARGUMENT_FORMAT","-2069","入参格式错误"),
		new CardReadError("ERROR_LOGIC_MON_LOAD","-2070","逻辑加密卡月票圈存失败"),
		new CardReadError("ERROR_LOGIC_MON_BALANCE","-2071","读取逻辑加密卡月票余额失败"),
		new CardReadError("ERROR_LOGIC_MON_INVALID","-2072","当前月月票无效"),
		new CardReadError("ERROR_GET_CITY_CODE","-2073","获取城市代码出错"),
		new CardReadError("ERROR_GET_LOGIC_SEC","-2074","获取逻辑加密指定业务类型物理扇区出错"),
		new CardReadError("ERROR_GET_CPU_AID","-2075","获取CPU卡指定业务类型的应用标识出错"),
		new CardReadError("ERROR_LOGIC_WALLET_ERROR","-2076","钱包数据异常"),
		new CardReadError("ERROR_SAM_FILE_1001","-2077","SAM选择1001文件"),
		new CardReadError("ERROR_GET_EA_CODE","-2078","取外部认证码失败"),
		new CardReadError("ERROR_AUTH_CJMAC","-2079","认证建设部码失败"),
		new CardReadError("ERROR_TERM_INIT","-2080","终端初始化失败"),
		new CardReadError("ERROR_OPEN_COM","-2081","打开COM端口失败"),
		new CardReadError("ERROR_CLOSE_COMAsLong","-2082","打开COM端口失败BYCYF"),
		new CardReadError("ERROR_DES_KEY","-2083","解密错,请与技术部联系"),
		new CardReadError("ERROR_LOGOUT_HAVESTORE","-2084","签退失败,已记录文件"),
		new CardReadError("ERROR_SECTOR_OUT_OF_RANGE","-2085","扇区号超出范围"),
		new CardReadError("ERROR_GET_KEYA_BY_SECTOR","-2086","根据扇区号获取KEYA失败"),
		new CardReadError("ERROR_WRONG_APP_TYPE","-2087","应用类型错误"),
		new CardReadError("ERROR_DOWN_KEY","-2088","下载密钥失败"),
		new CardReadError("ERROR_GET_CPU_INFO","-2089","取得CPU信息时出错"),
		new CardReadError("ERROR_M1_DISABLE","-2088","M1无效"),
		new CardReadError("ERROR_M1_ENABLE","-2089","M1有效"),
		new CardReadError("ERROR_CPU_DISABLE","-2090","CPU无效"),
		new CardReadError("ERROR_CPU_ENABLE","-2091","CPU有效"),
		new CardReadError("ERROR_NO_CARD","-2092","无卡"),
		new CardReadError("ERROR_CALC_LOGIC_TAC","-2093","计算TAC错误"),
		new CardReadError("ERROR_INIT_PINPADKEY","-2094","自检初始化终端密码错误"),
		new CardReadError("ERROR_GET_KEYA","-2097","获取KEYA失败"),
		new CardReadError("ERROR_ANNUAL_VERIFY","-2098","月票年审失败"),
		new CardReadError("ERROR_GET_LOIGC_DIR","-2099","获取逻辑加密卡扇区目录失败"),
		new CardReadError("ERROR_GET_PIN","-2100","获取输入密码失败"),
		new CardReadError("ERROR_TERM_LOGIN","-2101","终端签到失败"),
		new CardReadError("ERROR_TERM_LOGOUT","-2102","终端签退失败"),
		new CardReadError("ERROR_TERM_SET_TIMEOUT","-2103","设置超时时间失败"),
		new CardReadError("ERROR_SAM_AUTH","-2104","SAM认证失败"),
		new CardReadError("ERROR_SELL_LOGIC_CARD","-2105","逻辑加密卡售卡失败"),
		new CardReadError("ERROR_LOGIC_LOCK","-2106","逻辑加密卡锁定失败"),
		new CardReadError("ERROR_CPU_LOCK","-2107","CPU锁定失败"),
		new CardReadError("ERROR_LOGIC_RECOVER","-2108","逻辑加密卡恢复流程失败"),
		new CardReadError("ERROR_LOGIC_MAC","-2109","卡片异常，请与技术部联系"),
		new CardReadError("ERROR_LOGIC_COUNTER_FFFF","-2110","卡片异常，请与技术部联系"),
		new CardReadError("ERROR_LOGIC_POINTER","-2111","卡片异常，请与技术部联系"),
		new CardReadError("ERROR_LOGIC_YP_UNABLE","-2112","月票未启用"),
		new CardReadError("ERROR_LOGIC_YP_BLACKLIST","-2113","月票被禁用"),
		new CardReadError("ERROR_LOGIC_NONLOCAL_CARD","-2114","外地卡"),
		new CardReadError("ERROR_ANNUAL_YEAR_OVERFLOW","-2115","年份超过范围"),
		new CardReadError("ERROR_CARD_UNAVAILABLE","-2116","卡未启用"),
		new CardReadError("ERROR_CARD_NORMAL","-2117","正常状态的卡，不能售卡"),
		new CardReadError("ERROR_GET_CPU_MT_INFO","-2118","读取CPU月票信息失败"),
		new CardReadError("ERROR_READ_3F02_0015","-2119","读取3F02-0015文件失败"),
		new CardReadError("ERROR_GET_CPU_MT_LOAD_RECORD","-2120","读取CPU月票应用充值交易记录失败"),
		new CardReadError("ERROR_READ_3F02_0006","-2121","读取3F02-0006文件失败"),
		new CardReadError("ERROR_MT_LOAD_INIT","-2122","月票应用圈存初始化失败"),
		new CardReadError("ERROR_MT_LOAD","-2123","月票应用圈存失败"),
		new CardReadError("ERROR_WRONG_MT_TYPE","-2124","错误的月票、年票类型"),
		new CardReadError("ERROR_MT_PURCHASE","-2125","月票消费失败"),
		new CardReadError("ERROR_MT_PURCHASE_INIT","-2126","月票消费初始化失败"),
		new CardReadError("ERROR_READ_DF_0005","-2127","读取0005文件失败"),
		new CardReadError("ERROR_SELECT_DF_3F01","-2128","选择3F01文件失败"),
		new CardReadError("ERROR_SELECT_DF_3F02","-2129","选择3F02文件失败"),
		new CardReadError("ERROR_CHECK_DF_3F10","-2130","选择3F10文件失败"),
		new CardReadError("ERROR_DOWNLOAD_EXT_APP","-2131","应用下载失败"),
		new CardReadError("ERROR_GET_APP_INFO","-2132","查询CPU应用信息失败"),
		new CardReadError("ERROR_UPDATE_APP_INFO","-2133","更新CPU信息失败"),
		new CardReadError("ERROR_MT_UNLOAD","-2134","月票充资撤销失败"),
		new CardReadError("ERROR_GET_CPU_VERSION_FIELDS","-2135","读取CPU区卡版本字段失败"),
		new CardReadError("ERROR_SELECT_DF_3F20","-2136","选择3F20文件"),
		new CardReadError("ERROR_3F01_LOCKED","-2137","3F01已经锁定"),
		new CardReadError("ERROR_LOCK_APP_3F01","-2138","3F01锁定失败"),
		new CardReadError("ERROR_UNLOCK_APP_3F01","-2139","3F01解锁失败"),
		new CardReadError("ERROR_KILL_LOGIC","-2140","删除逻辑加密区失败"),
		new CardReadError("ERROR_KILL_LOGIC_MT","-2141","关闭逻辑加密区月票钱包失败"),
		new CardReadError("ERROR_BAKUP_LOGIC_EP","-2142","备份逻辑加密区电子钱包失败"),
		new CardReadError("ERROR_SELECT_DF_3F10","-2143","选择3F10文件失败"),
		new CardReadError("ERROR_CPU_CARD_SELL","-2144","CPU卡售卡失败"),
		new CardReadError("ERROR_DES_ID","-2145","加密证件号错误"),
		new CardReadError("ERROR_DES_INFO","-2146","加密个人信息错误"),
		new CardReadError("ERROR_DES_ERROR","-2147","解密信息错误"),
		new CardReadError("ERROR_LOCK_APP_3F02","-2148","3F02锁定失败"),
		new CardReadError("ERROR_UNLOCK_APP_3F02","-2149","3F02解锁失败"),
		new CardReadError("ERROR_LOCK_APP_3F10","-2150","3F10锁定失败"),
		new CardReadError("ERROR_UNLOCK_APP_3F10","-2151","查询CPU应用信息失败"),
		new CardReadError("ERROR_GET_APP_INFO","-2151","3F10解锁失败"),
		new CardReadError("ERROR_CHECK_CARD_STATE","-2152","需要修复"),
		new CardReadError("ERROR_READ_CAPP_RECPRD","-2153","读取复合消费记录失败"),
		new CardReadError("ERROR_UPDATE_CAPP_RECPRD","-2154","更新复合消费记录失败"),
		new CardReadError("ERROR_PIN_DIFF","-2155","两次密码不一致")
	);


/* 查询错误码 */
function checkError(errno) {
	$(errors).each(function(i, err) {
		if (err.errno == errno) {
			//alertMsg.error("卡操作异常.\n错误代码: " + err.errno + ", 错误信息: " + err.errmsg);
			alertMsg.error("卡操作异常: " + err.errmsg);
			return;
		}
	});
}
//自行车应用返回代码
function BikeError(errcode ,errmsg) {
	this.errcode = errcode;
	this.errmsg = errmsg;
}
var bikeErrors = new Array(
		new BikeError("0001","查无相关信息"),
		new BikeError("0002","证件号码不合法或年龄越界"),
		new BikeError("0003","证件已开通租车功能"),
		new BikeError("0004","卡片已开通租车功能"),
		new BikeError("0005","原会员卡不存在或者原会员号已经注销不允许进行业务操作"),
		new BikeError("0006","旧卡片不允许直接换卡或重写"),
		new BikeError("0007","新卡已经被使用不能换卡"),
		new BikeError("0008","新旧会员信息心态不是换新卡"),
		new BikeError("0009","重写时传入的信息和系统中存在的信息不一致"),
		new BikeError("0010","会员卡卡状态与操作目的一致无需更新"),
		new BikeError("0011","卡片余额不足不允许解挂"),
		new BikeError("0012","退卡失败"),
		new BikeError("9999","请求不通过或其他异常")
	);
function checkBikeError(errcode) {
	$(bikeErrors).each(function(i, err) {
		if (err.errcode == errcode) {
			alertMsg.error(err.errmsg);
			return;
		}
	});
}